﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using So.ImageResizer.Models;

namespace So.ImageResizer.Drivers {
    [UsedImplicitly]
    public class ImageResizerSettingsPartDriver : ContentPartDriver<ImageResizerSettingsPart> {
        private const string TemplateName = "Parts/ImageResizer.Settings";
        // protected override string Prefix { get { return "ImageResizer.Settings"; } }

        //protected override DriverResult Display(ImageResizerSettingsPart part, string displayType, dynamic shapeHelper)
        //{
        //    return ContentShape("Parts_ImageResizerSettings", () => shapeHelper.Parts_ImageResizerSettings(
        //        ContentPart: part
        //    ));
        //}


        protected override DriverResult Editor(ImageResizerSettingsPart part, dynamic shapeHelper) {
            return ContentShape("Parts_ImageResizer_Settings", () => shapeHelper.EditorTemplate(
                TemplateName: TemplateName,
                Model: part,
                Prefix: Prefix
                                                                         ));
        }

        protected override DriverResult Editor(ImageResizerSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}